<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>五季芳禾</title>

    <link rel="stylesheet" href="/wjfh/css/iconfont.css">
    <link rel="stylesheet" type="text/css" href="/wjfh/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/wjfh/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/wjfh/css/style.css"/>
    <script src="/wjfh/js/flexible.js" type="text/javascript" charset="utf-8"></script>
</head>
<body id="body" >
<div id="idata" v-cloak style="display: none">
    <div class="resgcontain">
        <div class="banner">
            <img src="/wjfh/img/banner.jpg">
            <span class="shareIcon icon iconfont">&#xe656;</span>
        </div>
        <div class="welcomeYu">欢迎您！{{name}} <span class="layui-badge layui-bg-orange">{{level}}</span>
            <p v-if="deptIds !=1 && deptIds !=2">您本月与上月累计已完成业绩【<span style="color: #f0ad4e">{{showgoodsnums}}</span>】件,下一等级为【<span style="color: #f0ad4e">{{deptIds | filtersDj}}</span>】,升级后您将获得更大的优惠哦！</p>
        </div>
    </div>
    <div class="resgcontain">
        <div class="layui-row">
            <div class="layui-col-xs3 mbnum" :class="{mb0:deptIds ==1}">
                <div class="index_navIcon">
                    <a href="/goodsManager/page/ddgl">
                        <span class="icon iconfont indexnavicon bgcolor1">&#xe651;</span>
                        <div class="name">我要发货</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3 mbnum" v-if = 'deptIds !=1'>
                <div class="index_navIcon">
                    <a href="/goodsManager/page/jinhuo">
                        <span class="icon iconfont indexnavicon bgcolor2">&#xe600;</span>
                        <div class="name">我要进货</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3 mbnum" :class="{mb0:deptIds ==1}">
                <div class="index_navIcon">
                    <a href="/goodsManager/page/wddd">
                        <span class="icon iconfont indexnavicon bgcolor3">&#xe601;</span>
                        <div class="name">订单管理</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3 mbnum" :class="{mb0:deptIds ==1}">
                <div class="index_navIcon">
                    <a href="/goodsManager/page/wdkc">
                        <span class="icon iconfont indexnavicon bgcolor4">&#xe63d;</span>
                        <div class="name">查看库存</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3" v-if = 'deptIds !=1'>
                <div class="index_navIcon">
                    <a href="/goodsManager/page/myPer">
                        <span class="icon iconfont indexnavicon bgcolor5">&#xe623;</span>
                        <div class="name">我的业绩</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3" v-if = 'deptIds !=1'>
                <div class="index_navIcon">
                    <a href="/goodsManager/page/myAward">
                        <span class="icon iconfont indexnavicon bgcolor6">&#xe608;</span>
                        <div class="name">我的奖励</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3" :class="{mb0:deptIds ==1}">
                <div class="index_navIcon">
                    <a href="/goodsManager/page/yaoqing">
                        <span class="icon iconfont indexnavicon bgcolor7">&#xe66d;</span>
                        <div class="name">邀请好友</div>
                    </a>
                </div>
            </div>
            <div class="layui-col-xs3"  v-cloak v-if = 'deptIds !=1'>
                <div class="index_navIcon">
                    <a href="/goodsManager/page/shengji">
                        <span class="icon iconfont indexnavicon bgcolor8">&#xe66b;</span>
                        <div class="name">我要升级</div>
                    </a>
                </div>
            </div>
        </div>
    </div>
    <div class="resgcontain">
        <div class="icontit"><span class="icon iconfont">&#xe653;</span>运营数据</div>
        <div class="layui-row">
            <div class="layui-col-xs4 yunyingdata">
                <a href="/goodsManager/page/ddgl">
                    <div class="data">{{order}}</div>
                    <div class="name">下级订单</div>
                </a>
            </div>
            <div class="layui-col-xs4 yunyingdata" v-if = 'deptIds !=1'>
                <a href="/goodsManager/page/myAward">
                    <div class="data">{{profit}}</div>
                    <div class="name">已获得奖励</div>
                </a>
            </div>
            <div class="layui-col-xs4 yunyingdata" v-if = 'deptIds !=1'>
                <a href="/goodsManager/page/wddd">
                    <div class="data">{{wddd}}</div>
                    <div class="name">我的订单</div>
                </a>
            </div>
            <div class="layui-col-xs4 yunyingdata">
                <a href="/goodsManager/page/xiaji">
                    <div class="data">{{subordinate}}</div>
                    <div class="name">我的下级</div>
                </a>
            </div>
            <div class="layui-col-xs4 yunyingdata">
                <a href="/goodsManager/page/wdkc">
                    <div class="data">{{stock}}</div>
                    <div class="name">我的库存</div>
                </a>
            </div>
        </div>
    </div>
    <div class="pubfooter">
        <div class="layui-row">
            <div class="layui-col-xs3 tcenter footnav active">
                <a href="/goodsManager/page/index">
                    <span class="layui-icon footicon">&#xe68e;</span>
                    <div class="name">首页</div>
                </a>
            </div>
            <div class="layui-col-xs3 tcenter footnav">
                <a href="/goodsManager/page/ddgl">
                    <span class="layui-icon footicon">&#xe656;</span>
                    <div class="name">订单</div>
                </a>
            </div>
            <div class="layui-col-xs3 tcenter footnav">
                <a href="/goodsManager/page/myPer">
                    <span class="icon iconfont footicon">&#xe623;</span>
                    <div class="name">业绩</div>
                </a>
            </div>
            <div class="layui-col-xs3 tcenter footnav">
                <a href="/goodsManager/page/xiaji">
                    <span class="layui-icon footicon">&#xe66f;</span>
                    <div class="name">下级</div>
                </a>
            </div>
        </div>
    </div>
    <div class="bantmbg" v-show="isnoshengji">
        <div class="shengjitongzhi" :class="{dd:isnoshengji == true}">
            <img class="huangguan" src="/wjfh/img/huangguan.png" alt="">
            <div class="sjhead">
                <h2>恭喜您</h2>
                <p>升级为<span>{{deptIds | filtersDj}}</span></p>
            </div>
            <div class="sjfoot"><button @click="closeIsnoshengji();">开启我的创业之旅</button></div>
        </div>
    </div>
</div>

<script src="/wjfh/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/wjfh/js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/wjfh/js/axios.js" type="text/javascript" charset="utf-8"></script>
<script>
    var idata = new  Vue({
        el:"#idata",
        data:{
            name:'',
            level:'',
            order:'0',
            profit:'0',
            stock:'0',
            subordinate:'0',
            invite:'0',
            deptIds:5,
            wddd:0,
            isnoshengji:false,
            showgoodsnums:0,
            userids:0,  //当前用户的id
            goodszongshu:0,   //商品总数
            tishiwenzi:0      //当前等级要求数量
        },
        filters:{
            filtersDj:function (num) {
                switch (num){
                    case 2:
                        return '联合创始人';
                        break;
                    case 3:
                        return '联合创始人';
                        break;
                    case 4:
                        return '总经销商';
                        break;
                    case 5:
                        return '经销商';
                        break;
                }
            }
        },
        methods: {
            shengjifun:function (nums,dpid,firstisno) {

                var newDeptIds = 0;
                switch (dpid){
                    case 5:
                        if(nums >= 12 && nums < 36){
                            newDeptIds = 4;
                        }else if(nums >= 36 && nums < 120){
                            newDeptIds = 3
                        }else if(nums >= 120){
                            newDeptIds = 2;
                        }else{
                            //console.log('不用升级');
                            return false;
                        }
                    break;
                    case 4:

                        if(nums >= 36 && nums < 120){
                            newDeptIds = 3
                        }else if(nums >= 120){
                            newDeptIds = 2;
                        }else{
                           // console.log('不用升级');
                            return false;
                        }
                    break;
                    case 3:
                       if(nums >= 120){
                            newDeptIds = 2;
                        }else{
                            //console.log('不用升级');
                            return false;
                        }
                    break;
                }

                $.ajax({         //这里是升级的接口
                    cache: true,
                    type: "POST",
                    data:{
                        userId: idata.userids,//用户id
                        deptId:idata.deptIds, //现在用户的等级id
                        newDeptId:newDeptIds// 要晋升的后的等级id

                    },
                    url: "/goodsManager/page/promotion",
                    error : function(request) {
                        layer.alert("Connection error");
                    },
                    success : function(data) {
                        if(firstisno == 0){
                            $.ajax({         //首单晋升更改状态
                                cache: true,
                                type: "POST",
                                data:{
                                    userId: idata.userids,//用户id
                                    oldStatus:'0',
                                    newStatus:'1' // 要晋升的状态

                                },
                                url: "/goodsManager/gmUserStatus/update",
                                error : function(request) {
                                    //layer.alert("Connection error");
                                },
                                success : function(data) {
                                    console.log('首次已升级');
                                    setTimeout(function(){
                                        idata.isnoshengji = true;
                                    }, 500);
                                }
                            });
                        }
                        setTimeout(function(){
                            idata.isnoshengji = true;
                        }, 500);
                    }
                });
            },
            closeIsnoshengji:function () {   //关闭升级弹框
                idata.isnoshengji = false;
                layer.msg('系统正在重置等级，请稍后', {
                    icon: 16
                    ,time:2000
                    ,shade: 0.01
                },function () {
                    window.location.reload();
                });
            }
        },
        mounted: function () {

            layui.use(['jquery', 'form', 'layer'], function () {
                $ = layui.jquery,
                    form = layui.form,
                    layer = layui.layer;
                layer.ready(function(){
                    layer.load(1);
                });
                $('.shareIcon').on('click',function () {
                    layer.confirm('您确认要退出当前账号吗？', {
                        skin: 'layui-layer-molv', //样式类名
                        btn: ['确认','取消'] //按钮
                    }, function(){
                        parent.location.href = '/goodsManager/page/login';
                    }, function(){

                    });
                })
                $.ajax({         //获取用户数据
                    cache: true,
                    type: "POST",
                    url: "/goodsManager/retail/mine",
                    error: function (request) {
                        layer.alert("Connection error");
                    },
                    success: function (data) {
                        //console.log(data);
                        if (data.code == 500 ) {
                            parent.location.href = '/goodsManager/page/login';
                        } else if(data.code != 1){
                            idata.name = data.name;
                            idata.level = data.level;
                            idata.order = data.order;
                            idata.profit = data.profit;
                            idata.stock = data.stock;
                            idata.subordinate = data.subordinate;
                            idata.userids = data.userId;
                            var adv = data.deptId;
                            $.ajax({     //获取订单
                                cache: true,
                                type: "POST",
                                url: "/goodsManager/gmOrder/getMyOrder",
                                error : function(request) {
                                    layer.alert("Connection error");
                                },
                                success : function(data) {
                                    idata.deptIds = adv;
//                                    console.log(idata.deptIds);
                                    var date=new Date;
                                    var year=date.getFullYear();
                                    var month=date.getMonth()+1;

                                    console.log('获取订单');
                                    console.log(data);
                                    for (len in data){
                                        idata.wddd++;

                                        if(data[len].status == 2 && idata.deptIds !=2){   //1是未完成 2是已完成   等级2是联创 再不用升级
                                            if(month == 1){
                                                month = 13;
                                        }
//                                            else if((date.getMonth()+1) <10){
//                                                month='0'+(date.getMonth()+1);
//                                            }else{
//                                                month=date.getMonth()+1;
//                                            }


                                            //计算累计订单数要去掉首单
                                            if(data[len].type != 0){

                                                //这里要判断是本月跟上月的订单数
                                                if(data[len].createTime.split('-')[1].indexOf(month) != -1 || data[len].createTime.split('-')[1].indexOf(month -1) != -1){
                                                    for(goodsnubs in data[len].data){

                                                        idata.goodszongshu += data[len].data[goodsnubs].goodsNum;
                                                    }
                                                    idata.showgoodsnums = idata.goodszongshu;
                                                    idata.shengjifun(idata.goodszongshu,idata.deptIds,1);
                                                }


                                            }else{

                                                for(goodsnubs in data[len].data){
                                                    idata.goodszongshu += data[len].data[goodsnubs].goodsNum;
                                                }
                                                //这里判断首单已完成 首单商品多少件 就升什么等级
                                                $.ajax({   //判断用户首单有没有升级
                                                    cache: true,
                                                    type: "POST",
                                                    data:{
                                                        'userId':idata.userids
                                                    },
                                                    url: "/goodsManager/gmUserStatus/get",
                                                    error : function(request) {
                                                        layer.alert("Connection error");
                                                    },
                                                    success : function(data) {
                                                        //console.log(data);
                                                        if(data.profitStatus == '0'){
                                                            idata.shengjifun(idata.goodszongshu,idata.deptIds,0);
                                                        }else{
                                                            console.log('首单已经升级过了');
                                                        }
                                                        layer.closeAll('loading');
                                                    }
                                                });

                                            }
                                        }else{
                                            idata.goodszongshu = 0;
                                        }
                                    }

                                    if (idata.deptIds == 3){
                                        idata.tishiwenzi = 120;
                                    }
                                    //console.log("当前订单商品数为"+idata.goodszongshu+'当前用户等级id为'+idata.deptIds+'商品总数需大于等于'+idata.tishiwenzi);

                                    $("#idata").show();
                                    layer.closeAll('loading');

                                }
                            });

                        }else{
                            layer.msg(data.msg, {icon: 5,time: 1200});
                            layer.closeAll('loading');
                        }


                    }
                });


            })
        }
    })
</script>
</body>
</html>
